//
//  AppClickModifier.swift
//  TimMusic
//
//  Created by nkl on 2024/10/21.
//

import AppIntents
import Foundation
import SwiftUI

struct AppClickModifier: ViewModifier {
    var urlString: String
    var isStatic: Bool
    func body(content: Content) -> some View {
        if isStatic {
            return AnyView(
                content
            )
        } else {
            if #available(iOS 17.0, *) {
                let intent: MusicClickIntent = MusicClickIntent()
                intent.urlString = urlString
                return AnyView(
                    Button(intent: intent) {
                        content
                    }
                    .buttonStyle(.borderless)
                )
            } else if let url = URL(string: urlString) {
                return AnyView(
                    Link(destination: url) {
                        content
                    }
                )
            } else {
                return AnyView(
                    content
                )
            }
        }
    }
}
